package unitTests;
import pieces.*;
import mainClasses.*;


import junit.framework.TestCase;

public class KnightTest extends TestCase {
	Board board = new Board();
	
	/**
	 * Set up the board to test the upcoming methods
	 */
	protected void setUp() throws Exception {
		Knight knight = new Knight(5, 5, board, "White");
		board.add(knight);
		Pawn pawn1 = new Pawn(3, 4, board, "White");
		board.add(pawn1);
		Pawn pawn2 = new Pawn(4,5,board, "White");
		board.add(pawn2);
		Pawn pawn3 = new Pawn(7,5,board, "Black");
		board.add(pawn3);
		King king = new King(4,7,board, "Black");
		board.add(king);
		King king2 = new King(5,3,board, "White");
		board.add(king2);
		board.print();
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	/**
	 * Tests the movePossible() method in Knight class
	 * Knight can move in L shape which means move 2 block in one direction and move one block on perpendicular direction.
	 */
	public void testMovePossible() {
		Knight knight = new Knight(5, 5, board, "White");
		board.add(knight);
		assertTrue(knight.movePossible(7,4)); //True since that move is valid because this move matches the knight's moving pattern
		assertTrue(knight.movePossible(7,6));
		assertTrue(knight.movePossible(6,7));
		assertTrue(knight.movePossible(4,7)); //true since the piece at the destination is a enemy piece
		assertTrue(knight.movePossible(3,6));
		assertFalse(knight.movePossible(3,4));//this works since we can't move on top of our own pieces
		assertTrue(knight.movePossible(4,3)); //true since we can jump over pieces
		assertTrue(knight.movePossible(6,3)); //true since we can jump over pieces
		assertFalse(knight.movePossible(7,0)); //False since that move is invalid because this move does not matches the knight's moving pattern
		assertFalse(knight.movePossible(0,0));
		
	}
	
	/**
	 * This method tests if the Knight constructor works
	 */
	public void testKnight() {
		Knight knight = new Knight(5, 5, board, "White");
		assertTrue(knight.getX() == 5);							//check if the point is the given location 5,5
		assertTrue(knight.getY() == 5);
		assertTrue(knight.getType().equals(" Knight  "));		//checks if t is a knight piece
		assertTrue(knight.getSide().equals("White"));			//Check if it is a White piece.
	}
	
	/**
	 * This method tests the moveKnight() method
	 * This method uses the knightSwap() method in board class which dosen't require two kings on the board
	 * and used for the Knight Tour game.
	 * 
	 * It uses the same point used in the testMovePossible() method so if the move is possible then the piece should move.
	 */
	public void testMoveKnight() {
		Knight knight = new Knight(5, 5, board, "White");
		board.add(knight);
		
		knight.moveKnight(3,4);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		knight.moveKnight(7,0);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		knight.moveKnight(0,0);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		knight.moveKnight(1,3);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		knight.moveKnight(7,0);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		
		knight.moveKnight(7,4);
		assertTrue(knight.getX() == 7);							
		assertTrue(knight.getY() == 4);
		knight.move(5,5);
		
		knight.moveKnight(7,6);
		assertTrue(knight.getX() == 7);							
		assertTrue(knight.getY() == 6);
		knight.move(5,5);
		
		knight.moveKnight(6,7);
		assertTrue(knight.getX() == 6);							
		assertTrue(knight.getY() == 7);
		knight.move(5,5);
		
		knight.moveKnight(4,7);
		assertTrue(knight.getX() == 4);							
		assertTrue(knight.getY() == 7);
		knight.move(5,5);
		
		knight.moveKnight(3,6);
		assertTrue(knight.getX() == 3);							
		assertTrue(knight.getY() == 6);
		
	}
	
	
	
	/**
	 * Test id two pieces are equal.
	 */
	public void testIsEqual() {
		Knight knight = new Knight(5, 5, board, "White");
		King king = new King(4,7,board, "Black");
		assertTrue(knight.isEqual(knight));	//should be equal since they are same pieces.
		assertFalse(knight.isEqual(king));	//shoulden't be equal since they are different pieces.
	}
	
	/**
	 * This method tests the move() method in piece class.
	 * This method uses the swap() method in board class which require two kings on the board
	 * and it is used for the Chess Game.
	 * 
	 * It uses the same point used in the testMovePossible() method so if the move is possible then the piece should move.
	 */
	public void testMove() {
		Knight knight = new Knight(5, 5, board, "White");
		board.add(knight);
		
		knight.move(3,4);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		
		knight.move(7,0);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		
		knight.move(0,0);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		
		knight.move(1,3);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		
		knight.move(7,0);
		assertTrue(knight.getX() == 5);							
		assertTrue(knight.getY() == 5);
		
		
		knight.move(7,4);
		assertTrue(knight.getX() == 7);							
		assertTrue(knight.getY() == 4);
		knight.move(5,5);
		
		knight.move(7,6);
		assertTrue(knight.getX() == 7);							
		assertTrue(knight.getY() == 6);
		knight.move(5,5);
		
		knight.move(6,7);
		assertTrue(knight.getX() == 6);							
		assertTrue(knight.getY() == 7);
		knight.move(5,5);
		
		knight.move(4,7);
		assertTrue(knight.getX() == 4);							
		assertTrue(knight.getY() == 7);
		knight.move(5,5);
		
		knight.move(3,6);
		assertTrue(knight.getX() == 3);							
		assertTrue(knight.getY() == 6);
	}

}
